package com.wanjl.ssm01.mapper;

import com.wanjl.ssm01.entity.Tea;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title TeaMapper
 * @description
 * @create 2024/11/1
 */
@Repository
public interface TeaMapper {
    /**
     *
     * @return
     */
    @Select("SELECT * FROM tea")
    List<Tea> selectAll();

    /**
     * 添加茶叶信息
     * @param tea 茶叶
     * @return 受到影响的行数
     */
    @Insert("INSERT INTO tea VALUES (#{id},#{teaName},#{teaTypeId},#{ordered},#{description},#{status})")
    Integer insert(Tea tea);

    /**
     * 修改茶叶信息
     * @param tea 茶叶
     * @return 受到影响的行数
     */
    @Update("UPDATE tea " +
            "SET teaName=#{teaName},teaTypeId=#{teaTypeId}, ordered=#{ordered}," +
            "description=#{description},status=#{status} " +
            "WHERE id=#{id}")
    Integer update(Tea tea);

    /**
     * 根据id删除茶叶信息
     * @param id 茶叶id
     * @return 受到影响的行数
     */
    @Delete("DELETE FROM tea WHERE id=#{id}")
    Integer delete(Integer id);

    /**
     * 根据id查询单个茶叶信息
     * @param id 茶叶id
     * @return 茶叶信息
     */
    @Select("SELECT * FROM tea WHERE id=#{id}")
    Tea selectById(Integer id);
}
